package com.xd.pre.modules.tpshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xd.pre.modules.tpshop.domain.TpGoodsAttr;
import com.xd.pre.modules.tpshop.domain.TpGoodsAttribute;
import com.xd.pre.modules.tpshop.mapper.TpGoodsAttributeMapper;
import com.xd.pre.modules.tpshop.service.ITpGoodsAttributeService;
import com.xd.pre.modules.tpshop.virtuaBean.Attribute_virtual;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@Service
public class TpGoodsAttributeServiceImpl extends ServiceImpl<TpGoodsAttributeMapper, TpGoodsAttribute> implements ITpGoodsAttributeService {
    @Autowired
    TpGoodsAttributeMapper goodsAttributeMapper;

    @Override
    public List<TpGoodsAttribute> find_SPProductAttribute_list_byGoodsId(int parseInt) {
        LambdaQueryWrapper<TpGoodsAttribute> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(TpGoodsAttribute::getGoodsTypeId, parseInt);
        return list(lambdaQuery);
    }

    @Override
    public List<Attribute_virtual> Attribute2Virtual(String goodsId) { // 通用方法
        List<TpGoodsAttr> sp_list_part1 = new ArrayList<TpGoodsAttr>();
        List<TpGoodsAttribute> sp_list_part2 = new ArrayList<TpGoodsAttribute>();
        List<Attribute_virtual> av_list = new ArrayList<Attribute_virtual>();
        Attribute_virtual av = null;

        sp_list_part1 = find_SPProductAttribute_list_byGoodsId_part1(Integer.parseInt(goodsId)); // ga1
        sp_list_part2 = find_SPProductAttribute_list_byGoodsId_part2(Integer.parseInt(goodsId)); // ga2
        if (sp_list_part1 != null && !sp_list_part1.isEmpty() && sp_list_part2 != null && !sp_list_part2.isEmpty()) {
            for (int i = 0; i < sp_list_part1.size(); i++) {
                av = new Attribute_virtual(
                        sp_list_part2.get(i).getAttrId(),
                        sp_list_part2.get(i).getAttrName(),

                        sp_list_part1.get(i).getAttrValue(),
                        sp_list_part1.get(i).getAttrPrice(),
                        sp_list_part1.get(i).getGoodsId()
                );
                av_list.add(av);
            }
        }

        return av_list;
    }

    @Override
    public List<TpGoodsAttr> find_SPProductAttribute_list_byGoodsId_part1(Integer goodsId) {
        return goodsAttributeMapper.find_SPProductAttribute_list_byGoodsId_part1(goodsId);
    }

    @Override
    public List<TpGoodsAttribute> find_SPProductAttribute_list_byGoodsId_part2(Integer goodsId) {
        return goodsAttributeMapper.find_SPProductAttribute_list_byGoodsId_part2(goodsId);
    }



    @Override
    public List<TpGoodsAttr> find_SPProductAttribute_value_list_byAttrId_part1(Integer goodsAttrId) {
        return goodsAttributeMapper.find_SPProductAttribute_value_list_byAttrId_part1(goodsAttrId);
    }

    @Override
    public List<TpGoodsAttribute> find_SPProductAttribute_name_list_byAttrId_part2(Integer goodsAttrId) {
        return goodsAttributeMapper.find_SPProductAttribute_name_list_byAttrId_part2(goodsAttrId);
    }

    @Override
    public List<TpGoodsAttr> find_SPProductAttr_list_by_attr_id2(Integer attrId2) {
        return goodsAttributeMapper.find_SPProductAttr_list_by_attr_id2(attrId2);
    }

}
